package com.shengyin.ec.model.dao.account;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.Personal;


@Repository("personalUserDao")
public class PersonalDaoImpl extends BaseDaoImpl<Personal> implements
		PersonalDao {

	@Override
	public boolean checkUser(String username,String pwd) {
		try {
			ArrayList<Personal> list = (ArrayList<Personal>) super.find("From Personal p where p.username='"+username+"' and p.password='"+pwd+"'");
			if(list.size()==0)
			   return false;
			else
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
		
	}
	
   //add by wql 2012-3-20
	public Long getTotal(){
		return (Long)super.find("select count(*) from Personal").get(0);
	}

	@Override
	public List<Personal> getPersonalByUsername(String username){
				ArrayList<Personal> list = (ArrayList<Personal>) super.find("From Personal p where p.username like '"+username+"'");
				return list;
	}

	public List<Personal> getPersonalByUsername(String username,int offset,int pageSize){
		ArrayList<Personal> list = (ArrayList<Personal>) super.find("From Personal p where p.username like '"+username+"'");
		return list;
    }
	
	public List getPersonalList(int offset,int pagesize){
		return super.findByPage("from Personal personal", offset, pagesize);
	}

}
